package com.jiaoxiaobo;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/9/4 22:20
 **/
public class RabbitMQUtil {

    private static Connection connection;
    private static final String HOST_NAME="127.0.0.1";
    //	private static final String HOST_NAME="worker2";
    private static final int HOST_PORT=5672;

    public static final String QUEUE_HELLO="hello";
    public static final String QUEUE_WORK="work";
    public static final String QUEUE_PUBLISH="publish";

    private RabbitMQUtil() {}

    public static Connection getConnection() throws Exception {
        if (null == connection) {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(HOST_NAME);
            factory.setPort(HOST_PORT);
            factory.setUsername("guest");
            factory.setPassword("guest");
            factory.setVirtualHost("/mirror");
            connection = factory.newConnection();
        }
        return connection;
    }

}
